<template>
  <div class="wrap">
    <div class="title">
      <img src="../../images/main/par.png" alt>
      <span class="back" @click="backServer()">服务商管理</span>
      <img class="right" src="../../images/main/right.png" alt>
      <span>分佣设置</span>
    </div>
    <div class="body">
      <div class="list">
        <div class="list_input">
          <img class="red" src="../../images/main/red.png" alt>
          <span class="txt">活动佣金比例：</span>
          <!-- <input type="text" class="input date" value="" v-model="commission"><span class="year">%</span> -->
          <el-input type="text" maxlength="100" style="width: 278px;" placeholder="请输入佣金比例" @input="commissionInp" v-model="commission">
            <!-- <i slot="suffix" class="el-input__icon el-icon-date"></i> -->
            <template slot="append">%</template>
          </el-input>
        </div>
        <div class="submit" @click="saveCommission()">提交</div>
      </div>
    </div>
  </div>
</template>
<script>
import Global from "../tool/Global.vue";
import axios from "axios";
import qs from "qs";
export default {
  data() {
    return {
      commission: 0
    };
  },
  methods: {
    commissionInp() {
      let _this = this;
      setTimeout (() => {
        _this.commission = isNaN ( _this.commission ) ? 0 : _this.commission.toString().replace ( /\.|-/img, '' );
        _this.commission = _this.commission > 100 ? 100 : _this.commission;
        _this.commission = _this.commission.replace ( /\s+/img, '' );
      }, 10 );
    },
    /**
     * 返回合伙人管理页
     */
    backServer: function() {
      this.$router.push({
        path: "/main/server"
      });
    },
    /**
     * 获取合伙人详情
     */
    getParManDetails: function() {
      console.log(Global.userId);
      let that = this;
      axios({
        method: "post",
        url: `${that.$store.state.url}/tService/selectServiceDateils`,
        data: qs.stringify({
          id:Global.serverId
        })
      }).then(res => {
        if (res.data.code == 0) {
          that.commission = res.data.data.commission;

        } else {
        }
      });
    },
    /**
     * 设置分佣
     */
    saveCommission: function() {
      if(this.commission===''){
        this.$alert('请输入佣金比例');
        return false;
      }  
      let that = this;
      // if(this.commission > 100 ){
      //   this.$alert('佣金比例不能大于100')
      // }
      axios({
        method: "post",
        url: `${that.$store.state.url}/tService/updateCommission`,
        data: qs.stringify({
          id: Global.serverId,
          commission: this.commission
        })
      }).then(res => {
        if (res.data.code == 0) {
          this.$store.state.fn.success( '保存成功' ).then (() => {
            that.backServer()
          });
          let logData = {
                loginTime:this.$cookie.get("loginTime"),
                account:this.$cookie.get("userAccount"),
                content:'服务商设置分佣',
              operationTime:this.setDate(new Date()) + ' ' +this.setTime(new Date())
              }
              axios({
          method: "post",
          url: `${that.$store.state.url}/log/addLog`,
          data: qs.stringify(logData)
        }).then( (res) => {
          console.log(res,'222')
        })
        } else {
          that.$alert(res.msg);
        }
      });
    },
    /**
     * 根据时间毫秒数 返回年月日
     */
    setDate: function (str) {
        let times = new Date(str)
        return `${times.getFullYear()}-${times.getMonth()+1 < 10 ? '0' + (times.getMonth()+1) : times.getMonth()+1}-${times.getDate() < 10 ? '0' + times.getDate() : times.getDate()}`
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function (str) {
        let times = new Date(str)
        return `${times.getHours() < 10 ? '0' + times.getHours() : times.getHours()}:${times.getMinutes() < 10 ? '0' + times.getMinutes() : times.getMinutes()}:${times.getSeconds() < 10 ? '0' + times.getSeconds() : times.getSeconds()}`
    }
  },
  mounted() {
    this.getParManDetails();
  }
};
</script>
<style scoped>
.wrap {
  /* padding: 68px 136px;
  width: 100%; */
  width: 90%;
  margin: 40px auto;
}
.title {
  height: 33px;
  line-height: 33px;
  font-size: 24px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
}
.title span {
  float: left;
}
.title img {
  width: 28px;
  height: 26px;
  float: left;
  padding-top: 5px;
  margin-right: 10px;
}
.title .right {
  width: 11px;
  height: 18px;
  padding-top: 9px;
  margin-left: 5px;
  margin-right: 6px;
}
.body {
  /* border-radius: 6px; */
  /* width: 1490px; */
  /* height: 1237px;
  margin-top: 70px;
  margin-left: 48px;
  padding-left: 233px;
  padding-top: 90px; */
  /* box-sizing: border-box; */
}
.list {
  /* margin-left: 145px; */
  width: 796px;
  margin: 40px auto;
  padding: 60px 0;
  /* height: 478px; */
  background: #ffffff;
  box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.05);
}
.list_input {
  /* padding-top: 60px; */
  padding-left: 135px;
}
.firlist {
  margin-top: 0;
}
.red {
  width: 10px;
  height: 10px;
}
.txt {
  width: 127px;
  display: inline-block;
  text-align: left;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  font-weight: bold;
  color: #000000;
}
.input {
  background: #ffffff;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 278px;
  height: 40px;
  margin-left: 11px;
  padding-left: 10px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
  box-sizing: border-box;
  text-align: center;
}
.tips {
  font-family: PingFangSC-Regular;
  font-size: 14px;
  color: #727272;
  margin-left: 35px;
}
.upload {
  margin-top: 55px;
}
.uptitle {
  height: 25px;
  line-height: 25px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  font-weight: bold;
}
.upimg {
  margin-top: 21px;
}
.upimg img {
  width: 320px;
  height: 205px;
  float: left;
  margin-left: 195px;
}
.info {
  width: 475px;
  padding-top: 38px;
  float: left;
  margin-left: 90px;
}
.uptxt {
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
  height: 30px;
  line-height: 30px;
  margin-top: 15px;
}
.firtxt {
  margin-top: 0;
}
.btn {
  width: 255px;
  height: 55px;
  background: #085dab;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #ffffff;
  margin-top: 47px;
  text-align: center;
  line-height: 55px;
}
.clear {
  clear: both;
}
.radio {
  display: inline-block;
  padding-left: 25px;
}
.radio img {
  width: 25px;
  height: 25px;
  float: left;
  border-radius: 50%;
}
.radio span {
  width: 37px;
  height: 25px;
  line-height: 25px;
  margin-left: 17px;
  float: left;
  margin-right: 59px;
  font-weight: bold;
}
.dateNum {
  width: 256px;
  border-right: 0px;
}
.year {
  background: #085dab;
  border: 1px solid #979797;
  width: 45px;
  height: 38px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #ffffff;
  line-height: 40px;
  text-align: center;
  display: inline-block;
  font-weight: bold;
  margin-left: -3px;
}
.submit {
  background: #085dab;
  width: 255px;
  height: 55px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #ffffff;
  line-height: 55px;
  text-align: center;
  margin-top: 170px;
  margin-left: 270px;
  cursor: pointer;
}
.back {
  cursor: pointer;
}
</style>
